<?php

namespace app\api\controller;


use addons\cms\model\Block;
use app\common\controller\Api;
use app\common\model\Notice;

/**
 * 首页接口
 */
class Index extends Api
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     * 
     */
    public function index()
    {
        $notice = Notice::order('created_at', 'desc')->limit(3)->field('id,title')->select();
        $banner = Block::where('name','focus')->field('image,url')->select();
        $this->success('success', [
            'notice' => $notice,
            'banners' => $banner
        ]);
    }


    public function future()
    {
        $result = \app\common\model\Future::where('status', \app\common\model\Future::IS_OPEN)->select();
        foreach ($result as $key => $item) {
            $response = \app\common\library\FutureService::getInstance()->getComrms($item['symbol']);
            $item->data('info', $response->Obj[0]);
        }
        $this->success('success', $result);
    }

    public function hot_future()
    {
        $result = \app\common\model\Future::where('symbol', 'in', ['CFFEXIC','CFFEXIF','CFFEXIH'])
            ->select();
        foreach ($result as $key => $item) {
            $response = \app\common\library\FutureService::getInstance()->getComrms($item['symbol']);
            $item->data('info', $response->Obj[0]);
        }
        $this->success('success', $result);
    }

}
